<!-- 折线图 -->
<style lang="stylus" scoped>
.danweimultiples
  height 100px
  background-size 100% 100%
  .main
    width 100%
    height calc(100% - 100px)
    margin-top -15px
</style>


<template>
<div class="danweimultiples">
  <p class='danweimultiples' style='font-family:微软雅黑;font-size:16px;color:#0B903C;font-weight:bold;line-height:50px;'>重点场所、单位分布</p>
  <div class="main"></div>
</div>

</template>

<script>
import echarts from 'echarts'
import header from 'components/header/header'
import filter from 'components/filter/filter'
import axios from 'axios'
export default {
  data() {
    return {
      legendArr: [],
      color: this.$store.state.color,
      styleArr: [],
      myChart: {},
      name: ''
    }
  },
  watch: {
    too(val, oldVal) {
      console.log("watch=", val, oldVal)
    }
  },
  methods: {
    _init() {
      this.legendArr = this.myChart.getOption().series
      this.legendArr.forEach((data) => {
        data.selected = true;
      })
      this.$root.charts.push(this.myChart)
      window.addEventListener('resize', function() {
        this.myChart.resize()
      }.bind(this))
    }
  },
  components: {
    'v-header': header,
    'v-filter': filter
  },
  mounted() {
    // 基于准备好的dom，初始化echarts实例
    this.myChart = echarts.init(document.querySelector('.danweimultiples .main'))
    this.myChart.on("click", function(params) {
      // localStorage.setItem('areaname', params.name)
      // location.href = "/vue/#/anzhibangs?areaname=" + params.name;
    })
    axios.get(this.GLOBAL.BASE_URL + '/a/sys/area/mapData?name=平顶山市').then((res) => {
    // axios.get('static/data/Data1.json').then((res) => {
      if (res) {
        var arr = [];
        var countarr = [];
        $(res.data).each(function() {
          if (this.name !== "平顶山市") {
            var arr1 = this.value.split(",");
            countarr[countarr.length] = arr1[9];
            arr[arr.length] = this.name;
          }
        })
        localStorage.setItem('areadata', JSON.stringify(res.data));
        this.myChart.setOption({
          title: {
            show: true
          },
          tooltip: {
            trigger: 'axis'
          },
          legend: {
            show: false
          },
          toolbox: {
            show: false
          },
          color: this.color,
          calculable: true,
          xAxis: [{
            name: '地区',
            type: 'category',
            axisLine: {
              show: false
            },
            axisTick: {
              show: false
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: '#00AA5E'
              }
            },
            nameTextStyle: {
              color: 'rgba(0, 155, 86, 1)',
              fontWeight: 'bold'
            },
            axisLabel: {
              rotate: 50,
              textStyle: {
                color: 'rgba(11, 144, 60, 1)',
                fontWeight: 'bold',
                fontSize: '10'
              }
            },
            data: arr
          }],
          yAxis: [{
            axisLine: {
              show: false
            },
            nameLocation: 'end',
            nameGap: 20,
            nameRotate: 0,
            axisTick: {
              show: false
            },
            splitLine: {
              show: false
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: '#00AA5E'
              }
            },
            axisLabel: {
              textStyle: {
                color: 'rgba(11, 144, 60, 1)',
                fontSize: 14,
                fontWeight: 'bold'
              }
            },
            name: '数量',
            type: 'value',
            nameTextStyle: {
              color: 'rgba(11, 144, 60, 1)',
              fontWeight: 'bold'
            }
          }],
          series: [{
            name: '各县区分布',
            stack: 'stack2',
            type: 'bar',
            data: countarr,
            barWidth: 16,
            barGap: 0,
            color: ['rgba(0,115,86, 1)'],
            itemStyle: {
              normal: {
                barBorderRadius: [5, 5, 0, 0],
                label: {
                  formatter: function (params) {
                    if (params.value > 0) {
                      return params.value + "个";
                    } else {
                      return "";
                    }
                  },
                  show: true,
                  color: '#00AA5E',
                  position: 'top',
                  fontWeight: 'bold'
                }
              }
            }
          }]
        });
        this._init()
      }
    });
  }
}

</script>
